
<table id="record"></table>
<fieldset id="edit_boxs" style="width:1065px;border:solid 1px #A4BED4;margin-bottom:10px;margin-top:10px;margin-left:-1px;position:relative;">
    <legend>会议记录管理操作</legend>
    <form action="/oa/recordAdd" id="recordSubmit">
        <div>
            <input type="hidden" name="id" id="ClickRowID" value="">
            <input type="hidden" name="participant_id" id="staff_id" value="">
            <table style="width:100%;table-layout:fixed;">
                <tbody>
                <tr>
                    <td style="width:100px;">会议主题：</td>
                    <td style="width:150px;">
                        <input name="title" style="width: 250px;" id="ClickRowTitle" class="text required" required="true">
                    </td>
                </tr>
                <tr>
                    <td style="width:100px;">主持人：</td>
                    <td style="width:150px;">
                        <input name="host" id="ClickRowHost" value="<?=$user['user']?>" class="text required" value="" required="true">
                    </td>
                </tr>
                <tr>
                    <td style="width:100px;">预计开会时间：</td>
                    <td style="width:150px;">
                        <input name="forecastDate" id="ClickRowForecastDate" class="text date"  required="true">
                    </td>
                    <td style="width:100px;">
                        <input id="ClickRowForecastTime" name="forecastTime" required="true" style="width:80px;">
                    </td>
                </tr>
                <tr>
                    <td style="width:100px;">会议开始时间：</td>
                    <td style="width:150px;">
                        <input name="start_time" id="start_time" class="text date"  required="true">
                    </td>
                    <td style="width:100px;">
                        <input id="start_times" name="start_times"  style="width:80px;">
                    </td>
                </tr>
                <tr>
                    <td style="width:100px;">会议结束时间：</td>
                    <td style="width:150px;">
                        <input name="end_time" id="end_time" class="text date"  required="true">
                    </td>
                    <td style="width:100px;">
                        <input id="end_times" name="end_times"  style="width:80px;">
                    </td>
                </tr>
                <tr>
                    <td style="width:100px;">会议参与者：</td>
                    <td style="width:650px;">
                        <input name="participant" id="participant" class="text required"  required="true">
                    </td>
                </tr>
                <tr>
                    <td>会议内容：</td>
                    <td colspan="3"><textarea name="content" id="content" style="width:442px;height:40px;"></textarea></td>
                </tr>
                <tr>
                    <td>会议成果：</td>
                    <td colspan="3"><textarea name="minute_result" id="minute_result" style="width:442px;height:40px;"></textarea></td>
                </tr>
                <tr>
                    <td>备注：</td>
                    <td colspan="3"><textarea name="remark" id="ClickRowRemark" style="width:442px;height:40px;"></textarea></td>
                    <td colspan="2"><a href="javascript:void(0)" class="button" id="SaveButton"><span class="button-text">新增</span></a>&nbsp;&nbsp;<a href="javascript:void(0)" class="button" id="ResetButton"><span class="button-text">重置</span></a></td>
                </tr>
                </tbody>
            </table>
        </div>
    </form>
</fieldset>

<script type="text/javascript">
    var staff = eval('('+JS.STAFF+')');
    $(document).ready(function(){

        // 初期化DataGrid
        $('#record').datagrid({
            width:1080,
            height:250,
            nowrap: true,
            autoRowHeight: false,
            striped: true,
            url:'/oa/recordPattern/?aid='+staff.agency_id,
            sortName: 'id',
            remoteSort: false,
            queryParams:{},
            idField:'id',
            pagination:true,
            rownumbers:true,
            pageList:[10,30,50],
            frozenColumns:[[
                {field:'ck',checkbox:true},
            ]],
            columns:[[
                {field:'title',title:'标题',width:120},
                {field:'host',title:'主题人',width:220,rowspan:2,sortable:true,
                    sorter:function(a,b){
                        return (a>b?1:-1);
                    }
                },
                {field:'forecast_format',title:'预计开会时间',width:150,rowspan:2},
                {field:'start_time_format',title:'会议开始时间',width:150,rowspan:2},
                {field:'end_time_format',title:'会议结束时间',width:150,rowspan:2}
            ]],
            toolbar:
                    [{
                        id:'btnadd',
                        text:'新增会议记录',
                        iconCls:'icon-add',
                        handler:function(){
                            var rows = $('#record').datagrid('getSelections');
                            if( rows.length == 1 ){
                                var rowData = rows[0];
                                $('#ClickRowTitle').val(rowData.title);
                                $('#ClickRowHost').val(rowData.host);
                                $("#staff_id").val(rowData.participant);
                                $(".datebox input[type='text']").val(rowData.forecast_date_format);
                                $("input[name='forecastDate']").val(rowData.forecast_date_format);


                                $("#ClickRowForecastDate").next().find("input").val(rowData.forecast_date_format);
                                $("#ClickRowForecastTime").val(rowData.forecast_time_format);


                                $("#start_time").next().find("input").val(rowData.start_time_format_date);
                                $("#start_times").val(rowData.start_time_format_time);

                                $("#end_time").next().find("input").val(rowData.end_time_format_date);
                                $("#end_times").val(rowData.end_time_format_time);

                                $('#participant').val(rowData.participant_name);
                                $('#ClickRowRemark').val(rowData.remark);

                                $('#content').val(rowData.content);

                                $('#SaveButton span').text('新增');
                            }else{
                                parent.$.dooDialog.alert('您只能复制一条记录，请重新选择......');
                            }
                        }
                    },'-',{
                        id:'remove-l',
                        text:'删除选中会议',
                        iconCls:'icon-remove',
                        handler:function(){
                            var ids  = "";

                            parent.$.dooDialog.confirm("你确定要删除这个会议吗？",function(){
                                var rows = $('#record').datagrid('getSelections');
                                if( rows.length > 0 ){
                                    for(var i=0;i<rows.length;i++){
                                        if(i==0){
                                            ids = rows[i].id;
                                        }else{
                                            ids = ids + "," + rows[i].id;
                                        }
                                    }

                                    $.post('/oa/recordDel',{deleted:ids},function(data){
                                        if(data.code=='OK'){
                                            $("#record").datagrid('reload');
                                        }else{
                                            parent.$.dooDialog.alert('会议记录删除失败！');
                                        }
                                    },'json');
                                }else{
                                    parent.$.dooDialog.alert('您还没有选择要删除的记录，请选择......');
                                }
                            });
                        }
                    },'-',{
                        id:'edit-l',
                        text:'编辑会议记录',
                        iconCls:'icon-edit',
                        handler:function(){
                            var rows = $('#record').datagrid('getSelections');
                            if( rows.length == 1 ){
                                var rowData = rows[0];
                                $('#ClickRowID').val(rowData.id);
                                $('#ClickRowTitle').val(rowData.title);
                                $('#ClickRowHost').val(rowData.host);
                                $("#staff_id").val(rowData.participant);
                                $(".datebox input[type='text']").val(rowData.forecast_date_format);
                                $("input[name='forecastDate']").val(rowData.forecast_date_format);


                                $("#ClickRowForecastDate").next().find("input").val(rowData.forecast_date_format);
                                $("#ClickRowForecastTime").val(rowData.forecast_time_format);


                                $("#start_time").next().find("input").val(rowData.start_time_format_date);
                                $("#start_times").val(rowData.start_time_format_time);

                                $("#end_time").next().find("input").val(rowData.end_time_format_date);
                                $("#end_times").val(rowData.end_time_format_time);

                                $('#participant').val(rowData.participant_name);
                                $('#ClickRowRemark').val(rowData.remark);
                                $('#content').val(rowData.content);

                                $('#SaveButton span').text('保存');
                            }else{
                                parent.$.dooDialog.alert('您只能编辑一条记录，请重新选择......');
                            }
                        }
                    },'-',{
                        text:'查看会议记录',
                        iconCls:'icon-search',
                        handler:function(){
                            var rows = $('#record').datagrid('getSelections');
                            if( rows.length == 1 ){
                                var rowData = rows[0];
                                window.location.href = '/oa/recordView/?id='+(rowData.id);

                                $('#SaveButton span').text('保存');
                            }else{
                                parent.$.dooDialog.alert('您只能编辑一条记录，请重新选择......');
                            }
                        }
                    }],
            onSelect:function(rowIndex, field, value){
                $('#ClickRowID').val('0');
                $('#ClickRowName').val('');
                $('#ClickRowTypes').val('');
                $('#ClickRowBrand').val('');
                $('#ClickRowPattern').val('');
                $('#ClickRowPrice,input[name="price"]').val('');
                $('#ClickRowSum,input[name="sum"]').val('');
                $('#ClickRowRemark').val('');
            },
            onLoadSuccess:function(){
                if (staff.manage_agency) {

                } else {
                    $('#btnadd').hide();
                    $('#remove-l').hide();
                    $('#edit-l').hide();
                    $('#edit_boxs').hide();
                }
            }
        });


        // 变更提交
        $('a#SaveButton').click(function(){
            // 数据检测
            var isValid = false;
            $("input.required").each(function(){
                if($(this).validatebox('isValid') == false){
                    isValid = true;
                    return false;
                }
            });

            if ($("input[name='forecastDate']").val() == '') {
                isValid = true;
                return false;
            }

            // 检测结果
            if(isValid){
                return false
            }

            // 数据提交
            $.post($('form#recordSubmit').attr('action'),$('form#recordSubmit').serializeArray(),function(data){
                if(data.code=='OK'){
                    $("#record").datagrid('reload');
                    $('input.text,input.number,input.count').each(function(){
                        $(this).val('');
                    });
                    $('input[name="title"]').val('');
                    $('#ClickRowRemark').val('');
                    parent.$.dooDialog.alert('会议记录成功！');
                    return true;
                }else{
                    parent.$.dooDialog.alert('会议记录失败！');
                    return false;
                }
            },'json');
        });

        // 重置
        $('a#ResetButton').click(function(){
            $('input.text,input.number,input.count').each(function(){
                $(this).val('');
            });

            $('input[name="price"]').val('');
            $('input[name="sum"]').val('');
            $('#ClickRowRemark').val('');
        });

        $('#ClickRowForecastTime').timespinner({
            showSeconds:true
        });
        $('#start_times').timespinner({
            showSeconds:true
        });
        $('#end_times').timespinner({
            showSeconds:true
        });

        /** 选择会议参与者 **/
        $("#participant").click(function(){

            $('#w').window('open');
        });



        $("a[type='hotCity']").click(function(){
            var did = $(this).attr('did');
            $(".staff").parent().hide();
            $("input[staff_id='"+did+"']").parent().show();
        });
        $("a[type='all']").click(function(){
            $(".staff").parent().show();
        });

        var staffarr = new Array();
        var staffnamearr = new Array();
        $("#sele_ok").click(function(){
            $(".staff:checked").each(function(){
                staffarr.push($(this).val());
                staffnamearr.push($(this).attr('title'))
            });
            $("#participant").val(staffnamearr.join(','));
            $("#staff_id").val(staffarr.join(','));
            $('#w').window('close');
        });
    });
</script>

